package com.bestescortbedsystem.service.impl;

import com.bestescortbedsystem.dao.SesUserFeedbackDao;
import com.bestescortbedsystem.entity.SesUserFeedback;
import com.bestescortbedsystem.entity.SesUserFeedbackExample;
import com.bestescortbedsystem.service.FeedbackService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Resource
    private SesUserFeedbackDao sesUserFeedbackDao;
    @Override
    public Map<String, Object> getAllFeedback(String minTime, String maxTime, String pageNumber, Integer pageSize) {
        List<SesUserFeedback> list=new ArrayList<>();
        PageHelper.startPage(Integer.parseInt(pageNumber), pageSize);
        SesUserFeedbackExample example=new SesUserFeedbackExample();
        SesUserFeedbackExample.Criteria criteria=example.createCriteria();
        if (minTime!=null&&!minTime.equals("")){
            criteria.andUserfeedbackdateLessThanOrEqualTo(minTime);
        }
        if (maxTime!=null&&!maxTime.equals("")){
            criteria.andUserfeedbackdateGreaterThanOrEqualTo(maxTime);
        }
        list=sesUserFeedbackDao.selectByExample1(example);
        PageInfo<SesUserFeedback> sesUserFeedbackPageInfo=new PageInfo<>(list);
        List<SesUserFeedback> feedbackList=sesUserFeedbackPageInfo.getList();
        Map<String,Object> map=new HashMap<>();
        map.put("fankui",feedbackList);
        map.put("page",sesUserFeedbackPageInfo);
        return map;
    }

    @Override
    public void deleteFeedback(String userfeedbackId) {
        sesUserFeedbackDao.deleteByPrimaryKey(Long.parseLong(userfeedbackId));
    }
}
